package org.tinyweb.render;

import java.io.PrintWriter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JavascriptRender extends Render {
    private static final Logger LOGGER = LoggerFactory.getLogger(JavascriptRender.class);
    private static final String CONTENT_TYPE = "text/javascript;charset=" + getEncoding();
    private String jsText;
    
    public JavascriptRender(String jsText){
        this.jsText = jsText;
    }
    
    @Override
    public void render() {
        PrintWriter writer = null;
        try {
            response.setContentType(CONTENT_TYPE);
            writer = response.getWriter();
            writer.write(jsText);
            writer.flush();
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
        } finally {
            if (writer != null){
                writer.close();
            }
        }
    }
    
}
